package cn.iocoder.yudao.module.cms.feedback.dal.mysql;

import cn.iocoder.yudao.framework.business.basic.dao.mapper.CoreMapper;
import cn.iocoder.yudao.framework.business.basic.dao.query.CoreLambdaQueryWrapper;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.cms.feedback.dal.dataobject.FeedbackDO;
import cn.iocoder.yudao.module.cms.feedback.vo.AdminFeedbackPageReqVO;
import cn.iocoder.yudao.module.cms.feedback.vo.FeedbackPageReqVO;
import org.apache.ibatis.annotations.Mapper;

/**
 * 意见反馈信息 Mapper
 *
 * @author 山野羡民（1032694760@qq.com）
 */
@Mapper
public interface FeedbackMapper extends CoreMapper<FeedbackDO> {

    default PageResult<FeedbackDO> selectPage(Long userId, FeedbackPageReqVO reqVO) {
        return selectPage(reqVO, new CoreLambdaQueryWrapper<FeedbackDO>()
                .eqIfPresent(FeedbackDO::getUserId, userId)
                .eqIfPresent(FeedbackDO::getCategoryId, reqVO.getCategoryId())
                .likeIfPresent(FeedbackDO::getContent, reqVO.getKeyword())
                .eqIfPresent(FeedbackDO::getStatus, reqVO.getStatus())
                .isNotNull(Boolean.TRUE.equals(reqVO.getHasPicture()), FeedbackDO::getPicUrls)
                .orderByDesc(FeedbackDO::getId)
                .orderByAsc(FeedbackDO::getCategoryId));
    }

    default PageResult<FeedbackDO> selectPage(AdminFeedbackPageReqVO reqVO) {
        return selectPage(reqVO, new CoreLambdaQueryWrapper<FeedbackDO>()
                .eqIfPresent(FeedbackDO::getUserId, reqVO.getUserId())
                .likeIfPresent(FeedbackDO::getNickname, reqVO.getNickname())
                .eqIfPresent(FeedbackDO::getMobile, reqVO.getMobile())
                .eqIfPresent(FeedbackDO::getCategoryId, reqVO.getCategoryId())
                .likeIfPresent(FeedbackDO::getContent, reqVO.getKeyword())
                .eqIfPresent(FeedbackDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(FeedbackDO::getCreateTime, reqVO.getCreateTime())
                .isNotNull(Boolean.TRUE.equals(reqVO.getHasPicture()), FeedbackDO::getPicUrls)
                .orderByAsc(FeedbackDO::getCategoryId)
                .orderByDesc(FeedbackDO::getId));
    }

}
